﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using OfficeBusiness.Model;

namespace OfficeBusiness.ViewModel
{
    public class SelectViewModel : ViewModelBase
    {
        private IList<string> items;
        private string selectedItem;
        private IBusinessModel businessModel;

        public SelectViewModel(IBusinessModel businessModel)
        {
            this.businessModel = businessModel;
        }

        public IList<string> Items
        {
            get
            {
                if (this.items == null)
                {
                    this.items = new List<string>();
                    this.items.Add("Department");
                    this.items.Add("Employees");
                    this.items.Add("Projects");
                    this.items.Add("Works");
                }

                return this.items;
            }
        }

        public string SelectedItem
        {
            get
            {
                return this.selectedItem;
            }

            set
            {
                this.selectedItem = value;
                this.DoSelectedBusiness();
                OnPropertyChanged("SelectedItem");
            }
        }

        private void DoSelectedBusiness()
        {
            SelectedBusiness selBusiness;
            if (this.SelectedItem == "Projects")
            {
                selBusiness = SelectedBusiness.Project;
            }
            else if (this.selectedItem == "Works")
            {
                selBusiness = SelectedBusiness.Work;
            }
            else if (this.selectedItem == "Employees")
            {
                selBusiness = SelectedBusiness.Employee;
            }
            else
            {
                selBusiness = SelectedBusiness.Department;
            }

            switch (selBusiness)
            {
                case SelectedBusiness.Department:
                    businessModel.DepartmentVisibility = Visibility.Visible;
                    break;

                case SelectedBusiness.Employee:
                    businessModel.EmployeesVisibility = Visibility.Visible;
                    break;

                case SelectedBusiness.Project:
                    businessModel.DepartmentVisibility = Visibility.Collapsed;
                    break;

                case SelectedBusiness.Work:
                    businessModel.EmployeesVisibility = Visibility.Collapsed;
                    break;
            }
        }
    }
}
